<?php

include_once("./_common.php");

//echo $wr_subject;

$wr_subject = urldecode($wr_subject);

if(trim($wr_subject)=='') {
    return "empty";
}

$result ='';
$write_table = $g4[write_prefix].$bo_table;

$row = sql_fetch(" select * from $g4[board_table] where bo_table = '$bo_table' ");
if($member[mb_level] >= $row[bo_write_level]) {

    if ($member[mb_id]) 
    {
        $mb_id = $member[mb_id];
        $wr_name = $member[mb_nick];
        $wr_password = $member[mb_password];
        $wr_email = $member[mb_email];
        $wr_homepage = $member[mb_homepage];

        $sql = " select min(wr_num) as min_wr_num from $write_table ";
        $row2 = sql_fetch($sql);
        $wr_num = $row2[min_wr_num] - 1;
        $wr_reply = "";

        $sql = " insert into $write_table
                    set wr_num = '$wr_num',
                        wr_reply = '$wr_reply',
                        wr_comment = 0,
                        ca_name = '$ca_name',
                        wr_option = '$html,$secret,$mail',
                        wr_subject = '$wr_subject',
                        wr_content = '상세 내용을 입력하세요.',
                        wr_link1 = '$wr_link1',
                        wr_link2 = '$wr_link2',
                        wr_link1_hit = 0,
                        wr_link2_hit = 0,
                        wr_trackback = '$wr_trackback',
                        wr_hit = 0,
                        wr_good = 0,
                        wr_nogood = 0,
                        mb_id = '$member[mb_id]',
                        wr_password = '$wr_password',
                        wr_name = '$wr_name',
                        wr_email = '$wr_email',
                        wr_homepage = '$wr_homepage',
                        wr_datetime = '$g4[time_ymdhis]',
                        wr_last = '$g4[time_ymdhis]',
                        wr_ip = '$_SERVER[REMOTE_ADDR]',
                        wr_1 = '$wr_1',
                        wr_2 = '$wr_2',
                        wr_3 = '$wr_3',
                        wr_4 = '$wr_4',
                        wr_5 = '$wr_5',
                        wr_6 = '$wr_6',
                        wr_7 = '$wr_7',
                        wr_8 = '$wr_8',
                        wr_9 = '$wr_9',
                        wr_10 = '$wr_10' ";
        sql_query($sql);

        $wr_id = mysql_insert_id();

        $result = $wr_id;

        // 부모 아이디에 UPDATE
        sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");

        // 새글 INSERT
        //sql_query(" insert into $g4[board_new_table] ( bo_table, wr_id, wr_parent, bn_datetime ) values ( '$bo_table', '$wr_id', '$wr_id', '$g4[time_ymdhis]' ) ");
        sql_query(" insert into $g4[board_new_table] ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '$bo_table', '$wr_id', '$wr_id', '$g4[time_ymdhis]', '$member[mb_id]' ) ");

        // 게시글 1 증가
        sql_query("update $g4[board_table] set bo_count_write = bo_count_write + 1 where bo_table = '$bo_table'");

    }

} else {
    $result = "error";
}


echo $result;
?>